package com.rdl.relation;

/**
 * 字段信息
 * 
 * @author Xairy
 * 
 */
public class FieldInfo {
	private String fieldName; // 字段名,运用到实体dao中
	private String sqlFieldName; // 运用到DB中的字段名称
	private FieldType type; // 字段类型
	private boolean bQuery; // 是否会被查询
	private String description; // 字段描述
	private boolean unique; // 是否是唯一的
	private boolean primary; // 是否是主键的一部分

	public FieldInfo() {
		this.bQuery = true;
		this.unique = false;
		this.primary = false;
	}

	public void setFieldName(String fieldName) {
		this.fieldName = fieldName;
	}

	public String getFieldName() {
		return fieldName;
	}

	/**
	 * @param type
	 *            the type to set
	 */
	public void setType(FieldType type) {
		this.type = type;
	}

	/**
	 * @return the type
	 */
	public FieldType getType() {
		return type;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getDescription() {
		return description;
	}

	public void setUnique(boolean isUnique) {
		this.unique = isUnique;
	}

	public boolean getUnique() {
		return unique;
	}

	public void setSqlFieldName(String sqlFieldName) {
		this.sqlFieldName = sqlFieldName;
		int pos = 0;
		int nextPos = 0;
		if (sqlFieldName.charAt(0) == 'F') {
			pos = 1;
		}
		StringBuffer buffer = new StringBuffer(128);
		boolean bNeedUp = false;
		for (int i = pos; pos < sqlFieldName.length(); ++pos) {
			if (sqlFieldName.charAt(pos) == '_') {
				bNeedUp = true;
			} else {
				if (bNeedUp) {
					buffer.append(Character.toUpperCase(sqlFieldName.charAt(pos)));
					bNeedUp = false;
				} else {
					buffer.append(sqlFieldName.charAt(pos));
				}
			}
		}
		this.fieldName = buffer.toString();
//		System.out.println("fieldName=" + fieldName);
	}

	public String getSqlFieldName() {
		return sqlFieldName;
	}

	public void setPrimary(boolean isPrimary) {
		this.primary = isPrimary;
	}

	public boolean isPrimary() {
		return primary;
	}

	public boolean isbQuery() {
		return bQuery;
	}

	public void setbQuery(boolean bQuery) {
		this.bQuery = bQuery;
	}

}
